package com.northpool.operator.param.custom;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.Objects;

public class DatasetParam {
    String dataSourceId;
    String tableName;
    String[] fields;
    String sqlFilter;

    public String getDataSourceId() {
        return dataSourceId;
    }

    public void setDataSourceId(String dataSourceId) {
        this.dataSourceId = dataSourceId;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String[] getFields() {
        return fields;
    }

    public void setFields(String fields) {
        if (StrUtil.isBlank(fields)) {
            this.fields = new String[0];
        }
        this.fields = StrUtil.splitTrim(fields, ",").toArray(new String[0]);
    }

    public String getSqlFilter() {
        return sqlFilter;
    }

    public void setSqlFilter(String sqlFilter) {
        this.sqlFilter = sqlFilter;
    }

    @Override
    public String toString() {
        return "DatasetParam{" +
                "dataSourceId='" + dataSourceId + '\'' +
                ", tableName='" + tableName + '\'' +
                ", fields=" + Arrays.toString(fields) +
                ", sqlFilter='" + sqlFilter + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DatasetParam that = (DatasetParam) o;
        return Objects.equals(dataSourceId, that.dataSourceId) && Objects.equals(tableName, that.tableName) && Objects.deepEquals(fields, that.fields) && Objects.equals(sqlFilter, that.sqlFilter);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dataSourceId, tableName, Arrays.hashCode(fields), sqlFilter);
    }
}
